//============================================================================================
/**
 * @file	zkn2_fight.h
 * @brief	金銀図鑑 登録完了画面処理
 * @author	Hiroyuki Nakamura
 * @date	08.10.02
 */
//============================================================================================
#include "common.h"

#include "system/snd_tool.h"
#include "system/wordset.h"

#include "poketool/poke_number.h"
#include "poketool/pokefoot.h"

#include "msgdata/msg.naix"
#include "msgdata/msg_zkn.h"

#include "application/zukanlist/zkn_world_text_sys.h"
#include "application/zukanlist/zkn_gira.h"
#include "application/zukanlist/zkn2_fight.h"

#include "zkn2_str.h"
#include "zkn2_tool.h"
#include "zukan_gra.naix"


//============================================================================================
//	定数定義
//============================================================================================

// BMPWIN ID
enum {
	BMPWIN_TITLE = 0,	//「とうろくしました」
	BMPWIN_POKE_NUM,	// ポケモン番号
	BMPWIN_POKE_NAME,	// ポケモン名
	BMPWIN_TYPE,		// ポケモン種類
	BMPWIN_INFO,		// 説明
	BMPWIN_HEIGHT,		//「たかさ」
	BMPWIN_H_NUM,		// 高さ
	BMPWIN_WEIGHT,		//「おもさ」
	BMPWIN_W_NUM,		// 重さ
	BMPWIN_MAX
};

// OBJ ID
enum {
	OBJID_BALL = 0,		// 捕獲ボール
	OBJID_TYPE1,		// タイプアイコン１
	OBJID_TYPE2,		// タイプアイコン２
	OBJID_FOOT,			// 足跡アイコン
	OBJID_MAX
};

#define	RES_MANAGER_MAX		( 4 )		// リソースマネージャーの数

// OBJデータ
typedef struct {
	CLACT_WORK_PTR  actwk;
	CLACT_U_RES_OBJ_PTR res[4];
}ZKN2_FIGHT_OBJ;

struct _ZKN2_FIGHT_WORK {
	ZKN2_FIGHT_DATA	dat;

	TCB_PTR	tcb;

	ARCHANDLE * ah;

	SOFT_SPRITE * ss;					// ソフトウェアスプライト

	GF_BGL_BMPWIN	win[BMPWIN_MAX];	// BMPWIN

	// OBJ
	CLACT_SET_PTR		clset;						// セルアクターセット
	CLACT_U_EASYRENDER_DATA render;					// レンダラーデータ
	CLACT_U_RES_MANAGER_PTR	res[RES_MANAGER_MAX];	// リソースマネージャ
	ZKN2_FIGHT_OBJ	obj[OBJID_MAX];					// OBJデータ

/*
	CATS_RES_PTR	crp;
	CATS_ACT_PTR	cap[OBJID_MAX];
*/
	u16	seq;
	u16	cnt;

	// 表示ポケモンデータ
	u32	mons;
	u32	frmno;
	u32	type1;
	u32	type2;

	BOOL end_flg;
};

// メインシーケンス
enum {
	MAINSEQ_INIT = 0,		// 画面初期化
	MAINSEQ_FADEIN_WAIT,	// フェードイン待ち
	MAINSEQ_VOICE_PLAY,		// 鳴き声再生
	MAINSEQ_VOICE_WAIT,		// 鳴き声終了待ち
	MAINSEQ_END,			// 終了
};

#define ZKN2FIGHT_TCB_PRI		( 0 )	// TCBのプライオリティ

// BMPWIN定義
#define	BMPWIN_STR_FRM			( GF_BGL_FRAME1_M )
//「とうろくしました」
#define	BMPWIN_TITLE_PX			( 2 )
#define	BMPWIN_TITLE_PY			( 0 )
#define	BMPWIN_TITLE_SX			( 28 )
#define	BMPWIN_TITLE_SY			( 2 )
#define	BMPWIN_TITLE_PAL		( 2 )
#define	BMPWIN_TITLE_CGX		( 1024 - BMPWIN_TITLE_SX * BMPWIN_TITLE_SY )
// ポケモン番号
#define	BMPWIN_POKE_NUM_PX		( 15 )
#define	BMPWIN_POKE_NUM_PY		( 3 )
#define	BMPWIN_POKE_NUM_SX		( 5 )
#define	BMPWIN_POKE_NUM_SY		( 2 )
#define	BMPWIN_POKE_NUM_PAL		( 0 )
#define	BMPWIN_POKE_NUM_CGX		( BMPWIN_TITLE_CGX - BMPWIN_POKE_NUM_SX * BMPWIN_POKE_NUM_SY )
// ポケモン名
#define	BMPWIN_POKE_NAME_PX		( 20 )
#define	BMPWIN_POKE_NAME_PY		( 3 )
#define	BMPWIN_POKE_NAME_SX		( 9 )
#define	BMPWIN_POKE_NAME_SY		( 2 )
#define	BMPWIN_POKE_NAME_PAL	( 0 )
#define	BMPWIN_POKE_NAME_CGX	( BMPWIN_POKE_NUM_CGX - BMPWIN_POKE_NAME_SX * BMPWIN_POKE_NAME_SY )
// ポケモン種類
#define	BMPWIN_TYPE_PX			( 15 )
#define	BMPWIN_TYPE_PY			( 5 )
#define	BMPWIN_TYPE_SX			( 16 )
#define	BMPWIN_TYPE_SY			( 2 )
#define	BMPWIN_TYPE_PAL			( 0 )
#define	BMPWIN_TYPE_CGX			( BMPWIN_POKE_NAME_CGX - BMPWIN_TYPE_SX * BMPWIN_TYPE_SY )
// 説明
#define	BMPWIN_INFO_PX			( 2 )
#define	BMPWIN_INFO_PY			( 17 )
#define	BMPWIN_INFO_SX			( 28 )
#define	BMPWIN_INFO_SY			( 6 )
#define	BMPWIN_INFO_PAL			( 1 )
#define	BMPWIN_INFO_CGX			( BMPWIN_TYPE_CGX - BMPWIN_INFO_SX * BMPWIN_INFO_SY )
//「たかさ」
#define	BMPWIN_HEIGHT_PX		( 18 )
#define	BMPWIN_HEIGHT_PY		( 11 )
#define	BMPWIN_HEIGHT_SX		( 5 )
#define	BMPWIN_HEIGHT_SY		( 2 )
#define	BMPWIN_HEIGHT_PAL		( 1 )
#define	BMPWIN_HEIGHT_CGX		( BMPWIN_INFO_CGX - BMPWIN_HEIGHT_SX * BMPWIN_HEIGHT_SY )
// 高さ
#define	BMPWIN_H_NUM_PX			( 23 )
#define	BMPWIN_H_NUM_PY			( 11 )
#define	BMPWIN_H_NUM_SX			( 8 )
#define	BMPWIN_H_NUM_SY			( 2 )
#define	BMPWIN_H_NUM_PAL		( 1 )
#define	BMPWIN_H_NUM_CGX		( BMPWIN_HEIGHT_CGX - BMPWIN_H_NUM_SX * BMPWIN_H_NUM_SY )
//「おもさ」
#define	BMPWIN_WEIGHT_PX		( 18 )
#define	BMPWIN_WEIGHT_PY		( 13 )
#define	BMPWIN_WEIGHT_SX		( 5 )
#define	BMPWIN_WEIGHT_SY		( 2 )
#define	BMPWIN_WEIGHT_PAL		( 1 )
#define	BMPWIN_WEIGHT_CGX		( BMPWIN_H_NUM_CGX - BMPWIN_WEIGHT_SX * BMPWIN_WEIGHT_SY )
// 重さ
#define	BMPWIN_W_NUM_PX			( 23 )
#define	BMPWIN_W_NUM_PY			( 13 )
#define	BMPWIN_W_NUM_SX			( 8 )
#define	BMPWIN_W_NUM_SY			( 2 )
#define	BMPWIN_W_NUM_PAL		( 1 )
#define	BMPWIN_W_NUM_CGX		( BMPWIN_WEIGHT_CGX - BMPWIN_W_NUM_SX * BMPWIN_W_NUM_SY )

#define	FNTCOL_LIST			( GF_PRINTCOLOR_MAKE( 2, 1, 0 ) )	// フォントカラー

#define	STR_TMP_BUF_SIZ		( 1024 )	// 文字列展開バッファサイズ

#define	CLACT_ID_COMMON		( 50712 )	// この画面で使用するセルアクターのID

// キャラリソースID
enum {
	CHR_ID_BALL = CLACT_ID_COMMON,
	CHR_ID_TYPEICON1,
	CHR_ID_TYPEICON2,
	CHR_ID_POKEFOOT,
	CHR_ID_MAX = CHR_ID_POKEFOOT - CLACT_ID_COMMON + 1
};
// パレットリソースID
enum {
	PAL_ID_BALL = CLACT_ID_COMMON,
	PAL_ID_TYPEICON1,
	PAL_ID_TYPEICON2,
	PAL_ID_POKEFOOT,
	PAL_ID_MAX = PAL_ID_POKEFOOT - CLACT_ID_COMMON + 1
};
// セルリソースID
enum {
	CEL_ID_BALL = CLACT_ID_COMMON,
	CEL_ID_TYPEICON1,
	CEL_ID_TYPEICON2,
	CEL_ID_POKEFOOT,
	CEL_ID_MAX = CEL_ID_POKEFOOT - CLACT_ID_COMMON + 1
};
// セルアニメリソースID
enum {
	ANM_ID_BALL = CLACT_ID_COMMON,
	ANM_ID_TYPEICON1,
	ANM_ID_TYPEICON2,
	ANM_ID_POKEFOOT,
	ANM_ID_MAX = ANM_ID_POKEFOOT - CLACT_ID_COMMON + 1
};

#define	RES_LOAD_NONE	( 0xffffffff )	// リソースを読み込まない

// OBJパレット
#define	PALSIZ_BALL			( 2 )			// パレット数：その他ＯＢＪ
#define	PALSIZ_TYPEICON		( 4 )			// パレット数：タイプアイコン
#define	PALSIZ_POKEFOOT		( 1 )			// パレット数：足跡

// ラベルのパレットアニメ
#define	LABEL_ANM_PX	( 0 )		// 開始Ｘ座標
#define	LABEL_ANM_PY	( 0 )		// 開始Ｙ座標
#define	LABEL_ANM_SX	( 32 )		// Ｘサイズ
#define	LABEL_ANM_SY	( 2 )		// Ｙサイズ
#define	LABEL_ANM_PAL1	( 0 )		// パレット１
#define	LABEL_ANM_PAL2	( 7 )		// パレット２
#define	LABEL_ANM_CNT1	( 16 )		// パレット変更カウント１
#define	LABEL_ANM_CNT2	( 32 )		// パレット変更カウント２


//============================================================================================
//	プロトタイプ宣言
//============================================================================================
static void Zkn2FightMain( TCB_PTR tcb, void * work );
static void LabelAnm( ZKN2_FIGHT_WORK * wk );

static void PokeParaWorkGet( ZKN2_FIGHT_WORK * wk );
static void BgInit( ZKN2_FIGHT_WORK * wk );
static void BgExit( ZKN2_FIGHT_WORK * wk );
static void BmpInit( ZKN2_FIGHT_WORK * wk );
static void BmpExit( ZKN2_FIGHT_WORK * wk );
static void CharManagerInit( ZKN2_FIGHT_WORK * wk );
static void CharManagerExit(void);
static void ObjInit( ZKN2_FIGHT_WORK * wk );
static void ObjExit( ZKN2_FIGHT_WORK * wk );
static void PokeSSInit( ZKN2_FIGHT_WORK * wk );
static void FadeInSet( ZKN2_FIGHT_WORK * wk );
static BOOL FadeInCheck( ZKN2_FIGHT_WORK * wk );
static void BallResLoad( ZKN2_FIGHT_WORK * wk );
static void BallResDelete( ZKN2_FIGHT_WORK * wk );
static void BallAdd( ZKN2_FIGHT_WORK * wk );
static void BallDelete( ZKN2_FIGHT_WORK * wk );
static void TypeIconResLoad( ZKN2_FIGHT_WORK * wk );
static void TypeIconResDelete( ZKN2_FIGHT_WORK * wk );
static void TypeIconAdd( ZKN2_FIGHT_WORK * wk );
static void TypeIconDelete( ZKN2_FIGHT_WORK * wk );
static void PokeFootResLoad( ZKN2_FIGHT_WORK * wk );
static void PokeFootResDelete( ZKN2_FIGHT_WORK * wk );
static void PokeFootAdd( ZKN2_FIGHT_WORK * wk );
static void PokeFootDelete( ZKN2_FIGHT_WORK * wk );
static void ClactResLoadHandle(
				CLACT_U_RES_OBJ_PTR * res_obj,
				CLACT_U_RES_MANAGER_PTR * res_man,
				int heap,
				ARCHANDLE * ah,
				int chr,
				int pal,
				int cel,
				int anm,
				int pal_max,
				int comm_res_chr,
				int comm_res_cel,
				int comm_res_pal,
				int comm_res_anm );
static void ClactResDelete(
				CLACT_U_RES_OBJ_PTR * res_obj,
				CLACT_U_RES_MANAGER_PTR * res_man );
static CLACT_U_RES_OBJ_PTR PaletteResLoadHandle(
				CLACT_U_RES_MANAGER_PTR res_man,
				int heap,
				ARCHANDLE * ah,
				int pal,
				int pal_max,
				int comm_res );

// キャラマネージャ関連
#define CHAR_MAN_WORKNUM		( 32 )				// ワーク数
#define CHAR_MAN_SIZE_MAIN		( 1024 * 0x40 )		// サイズ（メイン画面）
#define CHAR_MAN_SIZE_SUB		( 512 * 0x20 )		// サイズ（サブ画面）


//============================================================================================
//	グローバル変数
//============================================================================================

// ＢＭＰＷＩＮデータ
static const BMPWIN_DAT BmpWinData[] =
{
	{	//「とうろくしました」
		BMPWIN_STR_FRM, BMPWIN_TITLE_PX, BMPWIN_TITLE_PY,
		BMPWIN_TITLE_SX, BMPWIN_TITLE_SY, BMPWIN_TITLE_PAL, BMPWIN_TITLE_CGX
	},
	{	// ポケモン番号
		BMPWIN_STR_FRM, BMPWIN_POKE_NUM_PX, BMPWIN_POKE_NUM_PY,
		BMPWIN_POKE_NUM_SX, BMPWIN_POKE_NUM_SY, BMPWIN_POKE_NUM_PAL, BMPWIN_POKE_NUM_CGX
	},
	{	// ポケモン名
		BMPWIN_STR_FRM, BMPWIN_POKE_NAME_PX, BMPWIN_POKE_NAME_PY,
		BMPWIN_POKE_NAME_SX, BMPWIN_POKE_NAME_SY, BMPWIN_POKE_NAME_PAL, BMPWIN_POKE_NAME_CGX
	},
	{	// ポケモン種類
		BMPWIN_STR_FRM, BMPWIN_TYPE_PX, BMPWIN_TYPE_PY,
		BMPWIN_TYPE_SX, BMPWIN_TYPE_SY, BMPWIN_TYPE_PAL, BMPWIN_TYPE_CGX
	},
	{	// 説明
		BMPWIN_STR_FRM, BMPWIN_INFO_PX, BMPWIN_INFO_PY,
		BMPWIN_INFO_SX, BMPWIN_INFO_SY, BMPWIN_INFO_PAL, BMPWIN_INFO_CGX
	},
	{	//「たかさ」
		BMPWIN_STR_FRM, BMPWIN_HEIGHT_PX, BMPWIN_HEIGHT_PY,
		BMPWIN_HEIGHT_SX, BMPWIN_HEIGHT_SY, BMPWIN_HEIGHT_PAL, BMPWIN_HEIGHT_CGX
	},
	{	// 高さ
		BMPWIN_STR_FRM, BMPWIN_H_NUM_PX, BMPWIN_H_NUM_PY,
		BMPWIN_H_NUM_SX, BMPWIN_H_NUM_SY, BMPWIN_H_NUM_PAL, BMPWIN_H_NUM_CGX
	},
	{	//「おもさ」
		BMPWIN_STR_FRM, BMPWIN_WEIGHT_PX, BMPWIN_WEIGHT_PY,
		BMPWIN_WEIGHT_SX, BMPWIN_WEIGHT_SY, BMPWIN_WEIGHT_PAL, BMPWIN_WEIGHT_CGX
	},
	{	// 重さ
		BMPWIN_STR_FRM, BMPWIN_W_NUM_PX, BMPWIN_W_NUM_PY,
		BMPWIN_W_NUM_SX, BMPWIN_W_NUM_SY, BMPWIN_W_NUM_PAL, BMPWIN_W_NUM_CGX
	},
};


//--------------------------------------------------------------------------------------------
/**
 * 図鑑登録画面初期化
 *
 * @param	dat		外部設定データ
 *
 * @return	図鑑登録画面ワーク
 */
//--------------------------------------------------------------------------------------------
ZKN2_FIGHT_WORK * ZKN2FIGHT_Init( ZKN2_FIGHT_DATA * dat )
{
	ZKN2_FIGHT_WORK * wk;

	wk = sys_AllocMemory( dat->heapID, sizeof(ZKN2_FIGHT_WORK) );
	memset( wk, 0, sizeof(ZKN2_FIGHT_WORK) );

	memcpy( &wk->dat, dat, sizeof(ZKN2_FIGHT_DATA) );

	wk->ah = ArchiveDataHandleOpen( ARC_ZUKAN2_GRA, wk->dat.heapID );

	wk->seq = MAINSEQ_INIT;

	wk->end_flg = FALSE;

	wk->tcb = TCB_Add( Zkn2FightMain, wk, ZKN2FIGHT_TCB_PRI );

	return wk;
}

//--------------------------------------------------------------------------------------------
/**
 * 図鑑登録画面終了チェック
 *
 * @param	wk		図鑑登録画面ワーク
 *
 * @retval	"TRUE = 終了"
 * @retval	"FALSE = 処理中"
 */
//--------------------------------------------------------------------------------------------
BOOL ZKN2FIGHT_EndCheck( ZKN2_FIGHT_WORK * wk )
{
	return wk->end_flg;
}

//--------------------------------------------------------------------------------------------
/**
 * 図鑑登録削除
 *
 * @param	wk		図鑑登録画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2FIGHT_Exit( ZKN2_FIGHT_WORK * wk )
{
	ObjExit( wk );
	BmpExit( wk );
	BgExit( wk );

	ArchiveDataHandleClose( wk->ah );

	TCB_Delete( wk->tcb );

	sys_FreeMemoryEz( wk );
}

//--------------------------------------------------------------------------------------------
/**
 * 図鑑登録画面メインタスク
 *
 * @param	tcb
 * @param	work
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void Zkn2FightMain( TCB_PTR tcb, void * work )
{
	ZKN2_FIGHT_WORK * wk = work;

	switch( wk->seq ){
	case MAINSEQ_INIT:			// 画面初期化
		G2_BlendNone();
		PokeParaWorkGet( wk );
		BgInit( wk );
		BmpInit( wk );
		ObjInit( wk );
		PokeSSInit( wk );
		FadeInSet( wk );
		wk->seq = MAINSEQ_FADEIN_WAIT;
		break;

	case MAINSEQ_FADEIN_WAIT:	// フェードイン待ち
		if( FadeInCheck( wk ) == TRUE ){
			wk->seq = MAINSEQ_VOICE_PLAY;
		}
		break;

	case MAINSEQ_VOICE_PLAY:	// 鳴き声再生
		Snd_PMVoicePlayEx(
			PV_ZUKAN_NORMAL,
			wk->mons,
			PV_PTN_PARAM_NONE,
			PV_PTN_PARAM_NONE,
			PV_PTN_PARAM_NONE, 0 );
		wk->seq = MAINSEQ_VOICE_WAIT;
		break;

	case MAINSEQ_VOICE_WAIT:	// 鳴き声終了待ち
		if( Snd_PMVoicePlayCheck() == 0 ){
			wk->end_flg = TRUE;
			wk->seq = MAINSEQ_END;
		}
		break;

	case MAINSEQ_END:			// 終了
		break;
	}

//	CATS_Draw( wk->crp );
	CLACT_Draw( wk->clset );
	LabelAnm( wk );
}

//--------------------------------------------------------------------------------------------
/**
 * 表示に必要なポケモンデータ取得
 *
 * @param	wk		図鑑登録画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void PokeParaWorkGet( ZKN2_FIGHT_WORK * wk )
{
	BOOL fastMode;

	fastMode = PokeParaFastModeOn( wk->dat.pp );

	wk->mons  = PokeParaGet( wk->dat.pp, ID_PARA_monsno, NULL );
	wk->frmno = PokeParaGet( wk->dat.pp, ID_PARA_form_no, NULL );
	wk->type1 = PokeParaGet( wk->dat.pp, ID_PARA_type1, NULL );
	wk->type2 = PokeParaGet( wk->dat.pp, ID_PARA_type2, NULL );

	PokeParaFastModeOff( wk->dat.pp, fastMode );
}

//--------------------------------------------------------------------------------------------
/**
 * BG初期化
 *
 * @param	wk		図鑑登録画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void BgInit( ZKN2_FIGHT_WORK * wk )
{
	// 3D
	GF_BGL_PrioritySet( GF_BGL_FRAME0_M, 0 );
	GF_Disp_GX_VisibleControl( GX_PLANEMASK_BG0, VISIBLE_ON );

	{	// 文字
		GF_BGL_BGCNT_HEADER cnth= {
			0, 0, 0x800, 0, GF_BGL_SCRSIZ_256x256, GX_BG_COLORMODE_16,
			GX_BG_SCRBASE_0xf800, GX_BG_CHARBASE_0x00000, GX_BG_EXTPLTT_01,
			1, 0, 0, FALSE
		};
		GF_BGL_BGControlSet( wk->dat.bgl, GF_BGL_FRAME1_M, &cnth, GF_BGL_MODE_TEXT );
//		GF_BGL_ScrClear( wk->bgl, GF_BGL_FRAME1_M );
		GF_BGL_ClearCharSet( GF_BGL_FRAME1_M, 0x20, 0, wk->dat.heapID );
	}

	{	// 背景
		GF_BGL_BGCNT_HEADER cnth= {
			0, 0, 0x800, 0, GF_BGL_SCRSIZ_256x256, GX_BG_COLORMODE_16,
			GX_BG_SCRBASE_0xf000, GX_BG_CHARBASE_0x10000, GX_BG_EXTPLTT_01,
			2, 0, 0, FALSE
		};
		GF_BGL_BGControlSet( wk->dat.bgl, GF_BGL_FRAME2_M, &cnth, GF_BGL_MODE_TEXT );
	}

	{	// 使用してません
		GF_BGL_BGCNT_HEADER cnth= {
			0, 0, 0x800, 0, GF_BGL_SCRSIZ_256x256, GX_BG_COLORMODE_16,
			GX_BG_SCRBASE_0xe800, GX_BG_CHARBASE_0x10000, GX_BG_EXTPLTT_01,
			3, 0, 0, FALSE
		};
		GF_BGL_BGControlSet( wk->dat.bgl, GF_BGL_FRAME3_M, &cnth, GF_BGL_MODE_TEXT );
	}

	ArcUtil_HDL_BgCharSet(
		wk->ah, NARC_zukan_gra_zukan_gs_list_s_lz_NCGR,
		wk->dat.bgl, GF_BGL_FRAME2_M, 0, 0, TRUE, wk->dat.heapID );

	ArcUtil_HDL_ScrnSet(
		wk->ah, NARC_zukan_gra_zukan_gs_list01_s_lz_NSCR,
		wk->dat.bgl, GF_BGL_FRAME2_M, 0, 0, TRUE, wk->dat.heapID );

	PaletteWorkSet_ArcHandle(
		wk->dat.pfd, wk->ah,
		NARC_zukan_gra_zukan_gs_s_NCLR, wk->dat.heapID, FADE_MAIN_BG, 0, 0 );
}

//--------------------------------------------------------------------------------------------
/**
 * BG解放
 *
 * @param	wk		図鑑登録画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void BgExit( ZKN2_FIGHT_WORK * wk )
{
	GF_BGL_BGControlExit( wk->dat.bgl, GF_BGL_FRAME3_M );
	GF_BGL_BGControlExit( wk->dat.bgl, GF_BGL_FRAME2_M );
	GF_BGL_BGControlExit( wk->dat.bgl, GF_BGL_FRAME1_M );
}

//--------------------------------------------------------------------------------------------
/**
 * フェードイン設定
 *
 * @param	wk		図鑑登録画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void FadeInSet( ZKN2_FIGHT_WORK * wk )
{
	PaletteFadeReq( wk->dat.pfd, PF_BIT_MAIN_BG|PF_BIT_MAIN_OBJ, 0xffff, 1, 16, 0, 0 );
	SoftSpritePalFadeSet( wk->ss, 16, 0, 0, 0 );

	PaletteTrans_AutoSet( wk->dat.pfd, FALSE );
}

//--------------------------------------------------------------------------------------------
/**
 * フェードインチェック
 *
 * @param	wk		図鑑登録画面ワーク
 *
 * @retval	"TRUE = 処理中"
 * @retval	"FALSE = その他"
 */
//--------------------------------------------------------------------------------------------
static BOOL FadeInCheck( ZKN2_FIGHT_WORK * wk )
{
	if( PaletteFadeCheck( wk->dat.pfd ) == 0 &&
		SoftSpritePalFadeExist( wk->ss ) == FALSE ){
		return TRUE;
	}
	return FALSE;
}

//--------------------------------------------------------------------------------------------
/**
 * ラベルパレットアニメ
 *
 * @param	wk		図鑑登録画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void LabelAnm( ZKN2_FIGHT_WORK * wk )
{
	wk->cnt++;
	if( wk->cnt == LABEL_ANM_CNT1 ){
		GF_BGL_ScrPalChange(
			wk->dat.bgl, GF_BGL_FRAME2_M,
			LABEL_ANM_PX, LABEL_ANM_PY, LABEL_ANM_SX, LABEL_ANM_SY, LABEL_ANM_PAL2 );
		GF_BGL_LoadScreenV_Req( wk->dat.bgl, GF_BGL_FRAME2_M );
	}else if( wk->cnt == LABEL_ANM_CNT2 ){
		GF_BGL_ScrPalChange(
			wk->dat.bgl, GF_BGL_FRAME2_M,
			LABEL_ANM_PX, LABEL_ANM_PY, LABEL_ANM_SX, LABEL_ANM_SY, LABEL_ANM_PAL1 );
		GF_BGL_LoadScreenV_Req( wk->dat.bgl, GF_BGL_FRAME2_M );
		wk->cnt = 0;
	}
}

//--------------------------------------------------------------------------------------------
/**
 * BMP初期化
 *
 * @param	wk		図鑑登録画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void BmpInit( ZKN2_FIGHT_WORK * wk )
{
	MSGDATA_MANAGER * mman;
	WORDSET * wset;
	STRBUF * str;
	STRBUF * tmp;
	u32	i;

	for( i=0; i<BMPWIN_MAX; i++ ){
		GF_BGL_BmpWinAddEx( wk->dat.bgl, &wk->win[i], &BmpWinData[i] );
		GF_BGL_BmpWinDataFill( &wk->win[i], 0 );
	}

	// バトルが読み込んでいるのでいらない by AkitoMori 09.02.27
	// FontProc_LoadFont( FONT_TOUCH, wk->dat.heapID );

	mman = MSGMAN_Create( MSGMAN_TYPE_NORMAL, ARC_MSG, NARC_msg_zkn_dat, wk->dat.heapID );
	wset = WORDSET_Create( wk->dat.heapID );
	tmp  = STRBUF_Create( STR_TMP_BUF_SIZ, wk->dat.heapID );

	// タイトル
	ZKN2STR_Print(
		&wk->win[BMPWIN_TITLE], mman, ZKN_POKEGET_00,
		ZKN2STR_BMPWIN_CENTER(BMPWIN_TITLE_SX), 0, FONT_TOUCH, FNTCOL_LIST, ZKN2STR_PRINT_MODE_CENTER );

	// ポケモン番号
	WORDSET_RegisterNumber(
		wset, 0,
		PMNumber_GetPokeNumber(wk->dat.num_mode,wk->mons),
		3, NUM_MODE_ZERO, NUMBER_CODETYPE_DEFAULT );
	str = MSGMAN_AllocString( mman, ZNK_POKELIST_17 );
	WORDSET_ExpandStr( wset, tmp, str );
	ZKN2STR_PrintCore(
		&wk->win[BMPWIN_POKE_NUM], tmp,
		0, 0, FONT_TOUCH, FNTCOL_LIST, ZKN2STR_PRINT_MODE_LEFT );
	STRBUF_Delete( str );

	// ポケモン名
	str = ZKN_WT_GetPokeName( wk->mons, PM_LANG, wk->dat.heapID );
	ZKN2STR_PrintCore(
		&wk->win[BMPWIN_POKE_NAME], str,
		0, 0, FONT_TOUCH, FNTCOL_LIST, ZKN2STR_PRINT_MODE_LEFT );
	STRBUF_Delete( str );

	// ポケモン種類
	str = ZKN_WT_GetPokeType( wk->mons, PM_LANG, wk->dat.heapID );
	ZKN2STR_PrintCore(
		&wk->win[BMPWIN_TYPE], str,
		0, 0, FONT_TOUCH, FNTCOL_LIST, ZKN2STR_PRINT_MODE_LEFT );
	STRBUF_Delete( str );

	// 説明
	str = ZKN_WT_GetText( wk->mons, PM_LANG, 0, wk->dat.heapID );
	ZKN2STR_PrintCore(
		&wk->win[BMPWIN_INFO], str,
		4, 0, FONT_SYSTEM, FNTCOL_LIST, ZKN2STR_PRINT_MODE_LEFT );
	STRBUF_Delete( str );

	//「たかさ」
	ZKN2STR_Print(
		&wk->win[BMPWIN_HEIGHT], mman, ZNK_POKELIST_19,
		ZKN2STR_BMPWIN_CENTER(BMPWIN_HEIGHT_SX), 0, FONT_SYSTEM, FNTCOL_LIST, ZKN2STR_PRINT_MODE_CENTER );

	//「おもさ」
	ZKN2STR_Print(
		&wk->win[BMPWIN_WEIGHT], mman, ZNK_POKELIST_20,
		ZKN2STR_BMPWIN_CENTER(BMPWIN_WEIGHT_SX), 0, FONT_SYSTEM, FNTCOL_LIST, ZKN2STR_PRINT_MODE_CENTER );

	WORDSET_Delete( wset );
	MSGMAN_Delete( mman );

	// 高さ
	mman = MSGMAN_Create( MSGMAN_TYPE_NORMAL, ARC_MSG, ZKN_GIRA_GetHeightGmm(), wk->dat.heapID );
	ZKN2STR_Print(
		&wk->win[BMPWIN_H_NUM], mman, wk->mons,
		4, 0, FONT_SYSTEM, FNTCOL_LIST, ZKN2STR_PRINT_MODE_LEFT );
	MSGMAN_Delete( mman );

	// 重さ
	mman = MSGMAN_Create( MSGMAN_TYPE_NORMAL, ARC_MSG, ZKN_GIRA_GetGramGmm(), wk->dat.heapID );
	ZKN2STR_Print(
		&wk->win[BMPWIN_W_NUM], mman, wk->mons,
		4, 0, FONT_SYSTEM, FNTCOL_LIST, ZKN2STR_PRINT_MODE_LEFT );
	MSGMAN_Delete( mman );

	STRBUF_Delete( tmp );

	// バトルが読み込んでいるのでいらない by AkitoMori 09.02.27
	// FontProc_UnloadFont( FONT_TOUCH );

	for( i=0; i<BMPWIN_MAX; i++ ){
		GF_BGL_BmpWinOnVReq( &wk->win[i] );
	}
}

//--------------------------------------------------------------------------------------------
/**
 * BMP解放
 *
 * @param	wk		図鑑登録画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void BmpExit( ZKN2_FIGHT_WORK * wk )
{
	u32	i;

	for( i=0; i<BMPWIN_MAX; i++ ){
		GF_BGL_BmpWinDel( &wk->win[i] );
	}
}


//--------------------------------------------------------------------------------------------
/**
 * キャラマネージャー初期化
 *
 * @param	wk		図鑑登録画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void CharManagerInit( ZKN2_FIGHT_WORK * wk )
{
	CHAR_MANAGER_MAKE init = {
		CHAR_MAN_WORKNUM,
		CHAR_MAN_SIZE_MAIN,
		CHAR_MAN_SIZE_SUB,
		0
	};
	init.heap = wk->dat.heapID;
	InitCharManagerReg( &init, GX_OBJVRAMMODE_CHAR_1D_64K, GX_OBJVRAMMODE_CHAR_1D_32K );
}

//--------------------------------------------------------------------------------------------
/**
 * キャラマネ−ジャー削除
 *
 * @param	none
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void CharManagerExit(void)
{
	DeleteCharManager();
}

//--------------------------------------------------------------------------------------------
/**
 * リソースマネージャー初期化
 *
 * @param	wk		図鑑登録画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ResManInit( ZKN2_FIGHT_WORK * wk )
{
	int i;

	for( i=0; i<RES_MANAGER_MAX; i++ ){
		wk->res[i] = CLACT_U_ResManagerInit( 8, i, wk->dat.heapID );
	}
}

//--------------------------------------------------------------------------------------------
/**
 * リソースマネージャー削除
 *
 * @param	wk		図鑑登録画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ResManExit( ZKN2_FIGHT_WORK * wk )
{
	int i;

	for( i=0; i<RES_MANAGER_MAX; i++ ){
		CLACT_U_ResManagerDelete( wk->res[i] );
//		pp_res_manager[i] = NULL;
	}
}

//--------------------------------------------------------------------------------------------
/**
 * OBJ初期化
 *
 * @param	wk		図鑑登録画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ObjInit( ZKN2_FIGHT_WORK * wk )
{
	// セルアクターセット
	wk->clset = CLACT_U_SetEasyInit( 32, &wk->render, wk->dat.heapID );

	// 一応OAM面のクリア
	CLACT_UtilOamRamClear_Main( wk->dat.heapID );

	CharManagerInit( wk );
	ResManInit( wk );

	BallResLoad( wk );
	TypeIconResLoad( wk );
	PokeFootResLoad( wk );

	BallAdd( wk );
	TypeIconAdd( wk );
	PokeFootAdd( wk );

	GF_Disp_GXS_VisibleControl( GX_PLANEMASK_OBJ, VISIBLE_ON );
}

//--------------------------------------------------------------------------------------------
/**
 * モンスターボールのリソース読み込み
 *
 * @param	wk		図鑑登録画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void BallResLoad( ZKN2_FIGHT_WORK * wk )
{
	// リソース読み込み
	ClactResLoadHandle(
		wk->obj[OBJID_BALL].res,
		wk->res,
		wk->dat.heapID,
		wk->ah,
		NARC_zukan_gra_zukan_gs_obj_ball_s_lz_NCGR,
		NARC_zukan_gra_zukan_gs_obj_s_NCLR,
		NARC_zukan_gra_zukan_gs_obj_ball_s_lz_NCER,
		NARC_zukan_gra_zukan_gs_obj_ball_s_lz_NANR,
		PALSIZ_BALL,
		CHR_ID_BALL,
		PAL_ID_BALL,
		CEL_ID_BALL,
		ANM_ID_BALL );

	{
		u32	palnum = CLACT_U_PlttManagerGetPlttNo(
						wk->obj[OBJID_BALL].res[CLACT_U_PLTT_RES], NNS_G2D_VRAM_TYPE_2DMAIN );
		PaletteWorkSet_VramCopy( wk->dat.pfd, FADE_MAIN_OBJ, palnum * 16, PALSIZ_BALL * 0x20 );
	}
}

//--------------------------------------------------------------------------------------------
/**
 * モンスターボールのリソースを削除
 *
 * @param	wk		図鑑登録画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void BallResDelete( ZKN2_FIGHT_WORK * wk )
{
	ClactResDelete( wk->obj[OBJID_BALL].res, wk->res );
}

//--------------------------------------------------------------------------------------------
/**
 * タイプアイコンのリソース読み込み
 *
 * @param	wk		図鑑登録画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void TypeIconResLoad( ZKN2_FIGHT_WORK * wk )
{
	// リソース読み込み
	ClactResLoadHandle(
		wk->obj[OBJID_TYPE1].res,
		wk->res,
		wk->dat.heapID,
		wk->ah,
		ZKN2TOOL_TypeIconCharArcIDGet(wk->type1),
		NARC_zukan_gra_type_icon_NCLR,
		NARC_zukan_gra_type_icon_lz_NCER,
		NARC_zukan_gra_type_icon_lz_NANR,
		PALSIZ_TYPEICON,
		CHR_ID_TYPEICON1,
		PAL_ID_TYPEICON1,
		CEL_ID_TYPEICON1,
		ANM_ID_TYPEICON1 );

	ClactResLoadHandle(
		wk->obj[OBJID_TYPE2].res,
		wk->res,
		wk->dat.heapID,
		wk->ah,
		ZKN2TOOL_TypeIconCharArcIDGet(wk->type2),
//		NARC_zukan_gra_type_icon_NCLR,
		RES_LOAD_NONE,
		NARC_zukan_gra_type_icon_lz_NCER,
		NARC_zukan_gra_type_icon_lz_NANR,
		PALSIZ_TYPEICON,
		CHR_ID_TYPEICON2,
		PAL_ID_TYPEICON2,
		CEL_ID_TYPEICON2,
		ANM_ID_TYPEICON2 );

	{
		u32	palnum = CLACT_U_PlttManagerGetPlttNo(
						wk->obj[OBJID_TYPE1].res[CLACT_U_PLTT_RES], NNS_G2D_VRAM_TYPE_2DMAIN );
		PaletteWorkSet_VramCopy( wk->dat.pfd, FADE_MAIN_OBJ, palnum * 16, PALSIZ_TYPEICON * 0x20 );
/*
		palnum = CLACT_U_PlttManagerGetPlttNo(
						wk->obj[OBJID_TYPE2].res[CLACT_U_PLTT_RES], NNS_G2D_VRAM_TYPE_2DMAIN );
		PaletteWorkSet_VramCopy( wk->dat.pfd, FADE_MAIN_OBJ, palnum * 16, PALSIZ_TYPEICON * 0x20 );
*/
	}
}

//--------------------------------------------------------------------------------------------
/**
 * タイプアイコンのリソースを削除
 *
 * @param	wk		図鑑登録画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void TypeIconResDelete( ZKN2_FIGHT_WORK * wk )
{
	ClactResDelete( wk->obj[OBJID_TYPE1].res, wk->res );
//	ClactResDelete( wk->obj[OBJID_TYPE2].res, wk->res );
	CLACT_U_CharManagerDelete( wk->obj[OBJID_TYPE2].res[CLACT_U_CHAR_RES] );

	// リソース破棄
	CLACT_U_ResManagerResDelete( wk->res[CLACT_U_CHAR_RES], wk->obj[OBJID_TYPE2].res[CLACT_U_CHAR_RES] );
	CLACT_U_ResManagerResDelete( wk->res[CLACT_U_CELL_RES], wk->obj[OBJID_TYPE2].res[CLACT_U_CELL_RES] );
	CLACT_U_ResManagerResDelete( wk->res[CLACT_U_CELLANM_RES], wk->obj[OBJID_TYPE2].res[CLACT_U_CELLANM_RES] );

}

//--------------------------------------------------------------------------------------------
/**
 * 足跡のリソース読み込み
 *
 * @param	wk		図鑑登録画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void PokeFootResLoad( ZKN2_FIGHT_WORK * wk )
{
	ARCHANDLE * ah = ArchiveDataHandleOpen( PokeFootArcFileGet(), wk->dat.heapID );

	ClactResLoadHandle(
		wk->obj[OBJID_FOOT].res,
		wk->res,
		wk->dat.heapID,
		wk->ah,
		NARC_zukan_gra_foot_dmy_lz_NCGR,
		RES_LOAD_NONE,
		NARC_zukan_gra_foot_dmy_lz_NCER,
		NARC_zukan_gra_foot_dmy_lz_NANR,
		PALSIZ_POKEFOOT,
		CHR_ID_POKEFOOT,
		PAL_ID_POKEFOOT,
		CEL_ID_POKEFOOT,
		ANM_ID_POKEFOOT );

	wk->obj[OBJID_FOOT].res[CLACT_U_PLTT_RES] = PaletteResLoadHandle(
													wk->res[CLACT_U_PLTT_RES],
													wk->dat.heapID,
													ah,
													PokeFootPlttDataIdxGet(),
													PALSIZ_POKEFOOT,
													CHR_ID_POKEFOOT );

	{
		u32	palnum = CLACT_U_PlttManagerGetPlttNo(
						wk->obj[OBJID_FOOT].res[CLACT_U_PLTT_RES], NNS_G2D_VRAM_TYPE_2DMAIN );
		PaletteWorkSet_VramCopy( wk->dat.pfd, FADE_MAIN_OBJ, palnum * 16, PALSIZ_POKEFOOT * 0x20 );
	}

	ArchiveDataHandleClose( ah );
}

//--------------------------------------------------------------------------------------------
/**
 * 足跡のリソースを削除
 *
 * @param	wk		図鑑登録画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void PokeFootResDelete( ZKN2_FIGHT_WORK * wk )
{
	ClactResDelete( wk->obj[OBJID_FOOT].res, wk->res );
}

//--------------------------------------------------------------------------------------------
/**
 * OBJ削除
 *
 * @param	wk		図鑑登録画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ObjExit( ZKN2_FIGHT_WORK * wk )
{
	PokeFootDelete( wk );
	TypeIconDelete( wk );
	BallDelete( wk );

	PokeFootResDelete( wk );
	TypeIconResDelete( wk );
	BallResDelete( wk );

	ResManExit( wk );
	CharManagerExit();

	CLACT_DestSet( wk->clset );
}

//--------------------------------------------------------------------------------------------
/**
 * リソース読み込み
 *
 * @param	res_obj			リソースオブジェ
 * @param	res_man			リソースマネージャ
 * @param	heap			ヒープＩＤ
 * @param	ah				アークハンドル
 * @param	chr				キャラクタデータインデックス
 * @param	pal				パレットデータインデックス
 * @param	cel				セルデータインデックス
 * @param	anm				セルアニメインデックス
 * @param	comm_res_chr	キャラリソースＩＤ
 * @param	comm_res_pal	パレットリソースＩＤ
 * @param	comm_res_cel	セルリソースＩＤ
 * @param	comm_res_anm	アニメリソースＩＤ
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ClactResLoadHandle(
				CLACT_U_RES_OBJ_PTR * res_obj,
				CLACT_U_RES_MANAGER_PTR * res_man,
				int heap,
				ARCHANDLE * ah,
				int chr,
				int pal,
				int cel,
				int anm,
				int pal_max,
				int comm_res_chr,
				int comm_res_pal,
				int comm_res_cel,
				int comm_res_anm )
{
	// キャラクタデータ読み込み
	res_obj[CLACT_U_CHAR_RES] = CLACT_U_ResManagerResAddArcChar_ArcHandle(
									res_man[CLACT_U_CHAR_RES],
									ah,
									chr,
									TRUE,
									comm_res_chr,
									NNS_G2D_VRAM_TYPE_2DMAIN,
									heap );
	// 転送
	CLACT_U_CharManagerSetAreaCont( res_obj[CLACT_U_CHAR_RES] );
	// グラフィックデータだけ破棄
	CLACT_U_ResManagerResOnlyDelete( res_obj[CLACT_U_CHAR_RES] );

	// パレットデータ読み込み
	if( pal != RES_LOAD_NONE ){
		res_obj[CLACT_U_PLTT_RES] = PaletteResLoadHandle(
			res_man[CLACT_U_PLTT_RES],
			heap,
			ah,
			pal,
			pal_max,
			comm_res_pal );
	}

	// セルデータ読み込み
	res_obj[CLACT_U_CELL_RES] = CLACT_U_ResManagerResAddArcKindCell_ArcHandle(
									res_man[CLACT_U_CELL_RES],
									ah,
									cel,
									TRUE,
									comm_res_cel,
									CLACT_U_CELL_RES,
									heap );

	// セルアニメデータ読み込み
	res_obj[CLACT_U_CELLANM_RES] = CLACT_U_ResManagerResAddArcKindCell_ArcHandle(
									res_man[CLACT_U_CELLANM_RES],
									ah,
									anm,
									TRUE,
									comm_res_anm,
									CLACT_U_CELLANM_RES,
									heap );
}

//--------------------------------------------------------------------------------------------
/**
 * パレットリソース読み込み
 *
 * @param	res_man		リソースマネージャー
 * @param	heap		ヒープＩＤ
 * @param	ah			アークハンドル
 * @param	pal			パレットデータインデックス
 * @param	pal_max		パレット数
 * @param	comm_res	パレットリソースＩＤ
 *
 * @return	パレットリソースオブジェ
 */
//--------------------------------------------------------------------------------------------
static CLACT_U_RES_OBJ_PTR PaletteResLoadHandle(
				CLACT_U_RES_MANAGER_PTR res_man,
				int heap,
				ARCHANDLE * ah,
				int pal,
				int pal_max,
				int comm_res )
{
	CLACT_U_RES_OBJ_PTR	pal_res;

	pal_res = CLACT_U_ResManagerResAddArcPltt_ArcHandle(
				res_man,
				ah,
				pal,
				FALSE,
				comm_res,
				NNS_G2D_VRAM_TYPE_2DMAIN,
				pal_max,
				heap );
	// 転送
	CLACT_U_PlttManagerSetCleanArea( pal_res );
	// グラフィックデータだけ破棄
	CLACT_U_ResManagerResOnlyDelete( pal_res );

	return pal_res;
}

//--------------------------------------------------------------------------------------------
/**
 * リソース破棄
 *
 * @param	res_obj		リソースオブジェ
 * @param	res_man		リソースマネージャ
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ClactResDelete(
				CLACT_U_RES_OBJ_PTR * res_obj,
				CLACT_U_RES_MANAGER_PTR * res_man )
{
	CLACT_U_CharManagerDelete( res_obj[CLACT_U_CHAR_RES] );
	CLACT_U_PlttManagerDelete( res_obj[CLACT_U_PLTT_RES] );

	// リソース破棄
	CLACT_U_ResManagerResDelete( res_man[CLACT_U_CHAR_RES], res_obj[CLACT_U_CHAR_RES] );
	CLACT_U_ResManagerResDelete( res_man[CLACT_U_PLTT_RES], res_obj[CLACT_U_PLTT_RES] );
	CLACT_U_ResManagerResDelete( res_man[CLACT_U_CELL_RES], res_obj[CLACT_U_CELL_RES] );
	CLACT_U_ResManagerResDelete( res_man[CLACT_U_CELLANM_RES], res_obj[CLACT_U_CELLANM_RES] );
}

//--------------------------------------------------------------------------------------------
/**
 * セルアクターヘッダー作成
 *
 * @param	res_obj		リソースオブジェ
 * @param	res_man		リソースマネージャー
 * @param	head		ヘッダー作成先
 * @param	bg_pri		ＢＧとのプライオリティ
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ClactHeaderMake(
				CLACT_U_RES_OBJ_PTR * res_obj,
				CLACT_U_RES_MANAGER_PTR * res_man,
				CLACT_HEADER * head,
				int bg_pri )
{
	CLACT_U_MakeHeader(
		head,
		CLACT_U_ResManagerGetResObjID( res_obj[CLACT_U_CHAR_RES] ),
		CLACT_U_ResManagerGetResObjID( res_obj[CLACT_U_PLTT_RES] ),
		CLACT_U_ResManagerGetResObjID( res_obj[CLACT_U_CELL_RES] ),
		CLACT_U_ResManagerGetResObjID( res_obj[CLACT_U_CELLANM_RES] ),
		CLACT_U_HEADER_DATA_NONE,
		CLACT_U_HEADER_DATA_NONE,
		0,
		bg_pri,
		res_man[CLACT_U_CHAR_RES],
		res_man[CLACT_U_PLTT_RES],
		res_man[CLACT_U_CELL_RES],
		res_man[CLACT_U_CELLANM_RES],
		NULL,
		NULL );
}

//--------------------------------------------------------------------------------------------
/**
 * タイプアイコン追加
 *
 * @param	wk		図鑑登録画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void TypeIconAdd( ZKN2_FIGHT_WORK * wk )
{
	CLACT_ADD_SIMPLE	add;
	CLACT_HEADER	head;

	// ヘッダー作成
	ClactHeaderMake( wk->obj[OBJID_TYPE1].res, wk->res, &head, 1 );

	// 設定
	add.ClActSet	= wk->clset;
	add.ClActHeader	= &head;
	add.DrawArea	= NNS_G2D_VRAM_TYPE_2DMAIN;
	add.pri			= 0;
	add.heap		= wk->dat.heapID;
	add.mat.x		= 168 * FX32_ONE;
	add.mat.y		= 72 * FX32_ONE;
	wk->obj[OBJID_TYPE1].actwk = CLACT_AddSimple( &add );
//	CLACT_PaletteNoChg( wk->obj[OBJID_TYPE1].actwk, ZKN2TOOL_TypeIconPalNumGet(wk->type1) );
	CLACT_PaletteNoChgAddTransPlttNo( wk->obj[OBJID_TYPE1].actwk, ZKN2TOOL_TypeIconPalNumGet(wk->type1) );

	// タイプ2
//	ClactHeaderMake( wk->obj[OBJID_TYPE2].res, wk->res, &head, 1 );
	CLACT_U_MakeHeader(
		&head,
		CLACT_U_ResManagerGetResObjID( wk->obj[OBJID_TYPE2].res[CLACT_U_CHAR_RES] ),
		CLACT_U_ResManagerGetResObjID( wk->obj[OBJID_TYPE1].res[CLACT_U_PLTT_RES] ),
		CLACT_U_ResManagerGetResObjID( wk->obj[OBJID_TYPE2].res[CLACT_U_CELL_RES] ),
		CLACT_U_ResManagerGetResObjID( wk->obj[OBJID_TYPE2].res[CLACT_U_CELLANM_RES] ),
		CLACT_U_HEADER_DATA_NONE,
		CLACT_U_HEADER_DATA_NONE,
		0,
		1,
		wk->res[CLACT_U_CHAR_RES],
		wk->res[CLACT_U_PLTT_RES],
		wk->res[CLACT_U_CELL_RES],
		wk->res[CLACT_U_CELLANM_RES],
		NULL,
		NULL );

	add.ClActSet	= wk->clset;
	add.ClActHeader	= &head;
	add.DrawArea	= NNS_G2D_VRAM_TYPE_2DMAIN;
	add.pri			= 0;
	add.heap		= wk->dat.heapID;
	add.mat.x = (168+49) * FX32_ONE;
	add.mat.y = 72 * FX32_ONE;
	wk->obj[OBJID_TYPE2].actwk = CLACT_AddSimple( &add );
	if( wk->type2 == 0 || wk->type1 == wk->type2 ){
		CLACT_SetDrawFlag( wk->obj[OBJID_TYPE2].actwk, 0 );
	}else{
//		CLACT_PaletteNoChg( wk->obj[OBJID_TYPE2].actwk, ZKN2TOOL_TypeIconPalNumGet(wk->type2) );
		CLACT_PaletteNoChgAddTransPlttNo( wk->obj[OBJID_TYPE2].actwk, ZKN2TOOL_TypeIconPalNumGet(wk->type2) );
	}
}

//--------------------------------------------------------------------------------------------
/**
 * タイプアイコン削除
 *
 * @param	wk		図鑑登録画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void TypeIconDelete( ZKN2_FIGHT_WORK * wk )
{
	CLACT_Delete( wk->obj[OBJID_TYPE1].actwk );
	CLACT_Delete( wk->obj[OBJID_TYPE2].actwk );
}

//--------------------------------------------------------------------------------------------
/**
 * モンスターボール追加
 *
 * @param	wk		図鑑登録画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void BallAdd( ZKN2_FIGHT_WORK * wk )
{
	CLACT_ADD_SIMPLE	add;
	CLACT_HEADER	head;

	// ヘッダー作成
	ClactHeaderMake( wk->obj[OBJID_BALL].res, wk->res, &head, 1 );

	// 設定
	add.ClActSet	= wk->clset;
	add.ClActHeader	= &head;
	add.DrawArea	= NNS_G2D_VRAM_TYPE_2DMAIN;
	add.pri			= 0;
	add.heap		= wk->dat.heapID;
	add.mat.x		= 112 * FX32_ONE;
	add.mat.y		= 32 * FX32_ONE;
	wk->obj[OBJID_BALL].actwk = CLACT_AddSimple( &add );
}

//--------------------------------------------------------------------------------------------
/**
 * モンスターボール削除
 *
 * @param	wk		図鑑登録画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void BallDelete( ZKN2_FIGHT_WORK * wk )
{
	CLACT_Delete( wk->obj[OBJID_BALL].actwk );
}

//--------------------------------------------------------------------------------------------
/**
 * 足跡追加
 *
 * @param	wk		図鑑登録画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void PokeFootAdd( ZKN2_FIGHT_WORK * wk )
{
	NNSG2dImageProxy * ipc;
	u8 * buf;
	CLACT_ADD_SIMPLE	add;
	CLACT_HEADER	head;
	u32	cgx;

	// ヘッダー作成
	ClactHeaderMake( wk->obj[OBJID_FOOT].res, wk->res, &head, 1 );

	// 設定
	add.ClActSet	= wk->clset;
	add.ClActHeader	= &head;
	add.DrawArea	= NNS_G2D_VRAM_TYPE_2DMAIN;
	add.pri			= 0;
	add.heap		= wk->dat.heapID;
	add.mat.x		= 15 * 8 * FX32_ONE;
	add.mat.y		= 80 * FX32_ONE;
	wk->obj[OBJID_FOOT].actwk = CLACT_AddSimple( &add );

	buf = ZKN2TOOL_CgxAllocMake( wk->mons, wk->dat.heapID );
	ipc = CLACT_ImageProxyGet( wk->obj[OBJID_FOOT].actwk );
	cgx = NNS_G2dGetImageLocation( ipc, NNS_G2D_VRAM_TYPE_2DMAIN );

	DC_FlushRange( buf, ZKN2TOOL_CGX_SIZ );
	GX_LoadOBJ( buf, cgx, ZKN2TOOL_CGX_SIZ );

	sys_FreeMemoryEz( buf );
}

//--------------------------------------------------------------------------------------------
/**
 * 足跡削除
 *
 * @param	wk		図鑑登録画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void PokeFootDelete( ZKN2_FIGHT_WORK * wk )
{
	CLACT_Delete( wk->obj[OBJID_FOOT].actwk );
}

//--------------------------------------------------------------------------------------------
/**
 * 全てのＯＢＪを非表示にする
 *
 * @param	wk		図鑑登録画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
void ZKN2FIGHT_ObjVanish( ZKN2_FIGHT_WORK * wk )
{
	u32	i;

	for( i=0; i<OBJID_MAX; i++ ){
		CLACT_SetDrawFlag( wk->obj[i].actwk, 0 );
	}
}

//--------------------------------------------------------------------------------------------
/**
 * ポケモンのソフトウェアスプライト初期化
 *
 * @param	wk		図鑑登録画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void PokeSSInit( ZKN2_FIGHT_WORK * wk )
{
	SOFT_SPRITE_ARC	arc;

	PokeGraArcDataGetPP( &arc, wk->dat.pp, PARA_FRONT );

	wk->ss = SoftSpriteAdd(
				wk->dat.ssm, &arc,
				ZKN2FIGHT_POKEGRA_MAT_X, ZKN2FIGHT_POKEGRA_MAT_Y, 0,
				0, NULL, NULL );
}

//--------------------------------------------------------------------------------------------
/**
 * ポケモンのソフトウェアスプライトのポインタ取得
 *
 * @param	wk		図鑑登録画面ワーク
 *
 * @return	ソフトウェアスプライトのポインタ
 */
//--------------------------------------------------------------------------------------------
SOFT_SPRITE * ZKN2FIGHT_GetSoftSprite( ZKN2_FIGHT_WORK * wk )
{
	return wk->ss;
}